<template>
  <div>
    <el-dialog :title="ruleForm.id == '' ? '添加入库单' : '调拨单入库详情'" :visible.sync="addEditIsDialog_c"
      @close="resetForm('formName')" width="800px">
      <el-form :model="ruleForm" :rules="rules" ref="formName" label-width="120px" class="demo-ruleForm"
        :class="{ 'form-rules-show': seeType }">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司名称：" prop="companyId">
              <!-- <el-cascader v-model="ruleForm.companyId" placeholder="请选择公司名称" :options="companyArray" :props="{
                checkStrictly: true,
                value: 'id',
                label: 'name',
                children: 'childList',
              }" @change="changeTreeItem" clearable :disabled="seeType"></el-cascader> -->
              <span> {{ ruleForm.companyName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="基地名称：" prop="baseId">
              <!-- <el-select v-model="ruleForm.baseId" :disabled="seeType" placeholder="请选择基地名称" clearable>
                <el-option v-for="item in baseArray" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select> -->
              <span> {{ ruleForm.baseName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="入库单号" prop="baseId">
              <el-select v-model="ruleForm.code" placeholder="请选择入库单号" clearable>
                <el-option v-for="item in baseArray" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
     
        </el-row> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="车辆调拨单号：" prop="carTransferOrderCode">
              <!-- <el-input v-model="ruleForm.carTransferOrderCode" placeholder="无" clearable show-word-limit
                :disabled="seeType"></el-input> -->
              <span> {{ ruleForm.carTransferOrderCode }}</span>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="卵径：" prop="diameter">
              <!-- <el-input v-model="ruleForm.diameter" placeholder="请输入卵径" clearable show-word-limit
                :disabled="seeType"></el-input> -->
              <span> {{ ruleForm.diameter }}</span> (mm)

            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="鱼名：" prop="fishName">
              <!-- <el-input v-model="ruleForm.fishName" placeholder="请输入鱼名" clearable show-word-limit
                :disabled="seeType"></el-input> -->
              <span> {{ ruleForm.fishName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="转出鱼池名称：" prop="fishpondName">
              <!-- <el-input v-model="ruleForm.fishpondName" placeholder="请输入转出鱼池名称" clearable show-word-limit
                :disabled="seeType"></el-input> -->
              <span> {{ ruleForm.fishpondName }}</span>

            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="12">
            <el-form-item label="鱼尾数：" prop="num">
              <!-- <el-input v-model="ruleForm.num" placeholder="请输入鱼尾数" clearable show-word-limit
                :disabled="seeType"></el-input> -->
              <span> {{ ruleForm.num }}</span>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- <el-form-item label="性别" prop="sex">
              <el-date-picker v-model="ruleForm.sex" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item> -->
            <el-form-item label="性别：" prop="sex">
              <!-- <el-input v-model="ruleForm.sex" placeholder="请输入性别" clearable show-word-limit :disabled="seeType">

              </el-input> -->
              <span v-if="ruleForm.sex == 0">未鉴定</span>
              <span v-if="ruleForm.sex == 1">雄</span>
              <span v-if="ruleForm.sex == 2">雌</span>

            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="装鱼单兵" prop="workInUser">
              <el-input v-model="ruleForm.workInUser" placeholder="请输入鱼编码" clearable maxlength="50" show-word-limit
                :disabled="seeType"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="卸鱼日期" prop="workOutDate">
              <el-date-picker v-model="ruleForm.workOutDate" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="卸鱼单兵" prop="workOutUser">
              <el-input v-model="ruleForm.workOutUser" placeholder="请输入鱼编码" clearable maxlength="50" show-word-limit
                :disabled="seeType"></el-input>
            </el-form-item>
          </el-col>

        </el-row> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button @click="resetForm('formName')">取 消</el-button> -->
        <el-button class="btn-light-blue" @click="submitForm('formName')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script type="text/ecmascript-6">
import { getDataCarTransferOrderInDetail, saveObjFishpond } from "@/api/stock";
import { getCompanyInfoTree } from "@/api/company";
import { getSysCompanyBases, getSysFishTypes } from "@/api/system";

export default {
  components: {},
  props: {
    addEditId: {
      type: String,
      default: "",
    },
    addEditStatus: {
      type: String,
      default: "add",
    },
    addEditIsDialog: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      ruleForm: {
        // 表单字段
        id: "",
        addressArrival: "", // 到达地
        companyId: "",  // 公司Id
        carNumber: "", // 车牌号
        carUser: '', // 司机
        cvenCode: '', // 供应商编码
        typeName: '', // 入库类型名称
        baseId: "", // 基地Id
        updateName: '', // 创建修改人员名称
        batchCode: "", // 批次编码
        workInDate: "", // 装鱼日期
        workInUser: "", // 装鱼单兵
        workOutDate: '', // 卸鱼日期
        workOutUser: "", // 卸鱼单兵
      },
      rules: {


      },
      addEditIsDialog_c: false, // 弹窗是否显示
      seeType: true, // 是否禁用
      baseArray: [], // 基地集合
      companyArray: [], // 公司集合
      fishTypeArray: [], // 鱼类集合
      userType: "", // 用户类型（0超级管理员，1公司管理员）
    };
  },
  watch: {
    addEditIsDialog(val) {
      this.addEditIsDialog_c = val;
      if (this.addEditIsDialog_c) {
        // 添加
        if (this.addEditStatus == "add") {
          this.ruleForm.id = "";
          this.seeType = false;
        }

        // 编辑
        if (this.addEditStatus == "edit") {
          this.ruleForm.id = this.addEditId;
          this.seeType = true;
          this.getDetail();
        }

        // 查看
        if (this.addEditStatus == "see") {
          this.ruleForm.id = this.addEditId;
          this.seeType = true;
          this.getDetail();
        }

        this.userType = Number(window.localStorage.getItem("userType"));
      }
    },
  },
  methods: {
    // 详情
    getDetail() {
      getDataCarTransferOrderInDetail({ id: this.addEditId }).then((res) => {
        if (res.code == 200) {
          this.ruleForm = res.data;
          console.log(this.ruleForm);
          // 获取公司列表
          this.getCompanyInfoTree();

          this.getSysCompanyBases();

          this.getSysFishTypes();
        }
      });
    },
    // 提交
    submitForm(formName) {
      // this.$refs[formName].validate((valid) => {
      //   if (valid) {
      //     saveObjFishpond(this.ruleForm).then((res) => {
      //       if (res.code == 200) {
      //         this.$message({
      //           type: "success",
      //           message: res.msg,
      //         });

      //         // 关闭弹窗
      //         this.$parent.closeAddEdit();
      //         // 刷新列表
      //         this.$parent.onSubmit();
      //       }
      //     });
      //   }
      // });
      this.$parent.closeAddEdit();
    },
    // 取消
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.$parent.closeAddEdit();
    },
    // 获取公司列表
    getCompanyInfoTree() {
      if (this.ruleForm.userType === "") {
        return;
      }

      if (this.ruleForm.userType == 0) {
        // 超级管理员，公司只有一个总公司
        this.companyArray = [
          {
            id: 0,
            name: "总公司",
            parentId: 0,
          },
        ];
      } else {
        getCompanyInfoTree({}).then((res) => {
          if (res.code == 200) {
            this.companyArray = res.data;
          }
        });
      }
    },
    // 公司下拉切换
    changeTreeItem(val) {
      if (val) {
        this.ruleForm.companyId = val[val.length - 1];
      } else {
        this.ruleForm.companyId = "";
      }

      this.ruleForm.baseId = "";
      this.baseArray = [];

      // 获取基地列表
      this.getSysCompanyBases();
    },
    // 获取基地列表
    getSysCompanyBases() {
      if (this.ruleForm.companyId === "" || this.ruleForm.companyId == null) {
        return;
      }

      getSysCompanyBases({ id: this.ruleForm.companyId }).then((res) => {
        if (res.code == 200) {
          this.baseArray = res.data;
        }
      });
    },
    getSysFishTypes() {
      getSysFishTypes().then((res) => {
        if (res.code == 200) {
          this.fishTypeArray = res.data;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.demo-ruleForm {
  width: 95%;
  margin: 0 auto;
  padding-top: 10px;
}

.el-cascader {
  width: 100%;
}

.el-select {
  width: 100%;
}
</style>
